package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    /**
     * 线索跟进
     * @param tbClueTrackRecord
     */
    @Transactional
    public void add(ClueTrackRecordVo tbClueTrackRecord) {
        String username = SecurityUtils.getUsername();
        //更新线索表
        tbClueTrackRecordMapper.updateTbClue(tbClueTrackRecord);
        TbClueTrackRecord trackRecord = new TbClueTrackRecord();
        //将前端接收的对象拷贝 到TbClueTrackRecord对象中
        BeanUtils.copyProperties(tbClueTrackRecord,trackRecord);
        //设置用户
        trackRecord.setCreateBy(username);
        //插入线索跟进表
        tbClueTrackRecordMapper.add(trackRecord);
    }

    /**
     * 查询线索跟进记录列表
     * @param clueId
     * @return
     */
    public List<TbClueTrackRecord> find(Long clueId) {
        return tbClueTrackRecordMapper.findAll(clueId);
    }
}
